from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
from src import log
import pymysql


app = Flask(__name__)
CORS(app, supports_credentials=True)
pymysql.install_as_MySQLdb()
mysql_db = SQLAlchemy()


def init_app(config):
    app.config.from_pyfile(config)
    # Jsonify 返回结果显示中文
    app.config['JSON_AS_ASCII'] = False
    # 初始化Sqlalchemy
    mysql_db.init_app(app)
    mysql_db.app = app
    # 初始化Log
    log.init(app.config['LOG_FILE'])
    # blueprint registering...
    from src.api import common, dataTools, melon
    app.register_blueprint(common.blueprint)
    app.register_blueprint(dataTools.blueprint)
    app.register_blueprint(melon.blueprint)

    return app
